//-------------------------------------------------------------------
//  Main.c
//-------------------------------------------------------------------
#include <stdio.h>
//-------------------------------------------------------------------
#include "Top.h"
#include "Bigint.h"
#include "BigintEC.h"
#include "Poly.h"
#include "PolyEC.h"
//-------------------------------------------------------------------
extern	char	bigint_prime_ascii;
extern  char    bigint_order_ascii;
extern  FIELD2N poly_prime;
//-------------------------------------------------------------------
void main(void)
{
	char bpx_dec[MAXSTRING]   = "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296";
	char bpy_dec[MAXSTRING]   = "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5";
	char curva_dec[MAXSTRING] = "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC";
	char curvb_dec[MAXSTRING] = "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B";
	char k_dec[MAXSTRING]     = "7A1A7E52797FC8CAAA435D2A4DACE39158504BF204FBE19F14DBB427FAEE50AE";
	
	char testA[MAXSTRING]     = "1215352412153524121535241215352412153524121535241215352412153524";
	char testB[MAXSTRING]     = "c0895e81c0895e81c0895e81c0895e81c0895e81c0895e81c0895e81c0895e81";
	char testW[MAXSTRING]     = "10000000000000000000000000000000000000000000000000000000000000000";
	char n_p_hex[MAXSTRING]   = "FFFFFFFF00000002000000000000000000000001000000000000000000000001";
	char	Z1_dec[MAXSTRING] = "1";
	char	Z0_dec[MAXSTRING] = "0";


	BIGINT       prime;
	BIGINT_POINT bp; //p
	BIGINT_POINT bp1; //p
	BIGINT_POINT dp; //2p
	BIGINT_POINT tp; //p+2p
	BIGINT_POINT p5; //p+2p
	BIGINT_POINT kp,kp1; // kp
	BIGINT_CURVE curv;
	BIGINT       z1;
	BIGINT       t1;
	BIGINT        k;
	BIGINT        A,B,C,q,W,zero;
	char out[MAXSTRING];
	int i;


	
	
	//hex_to_bigint(testW, &W);
	//hex_to_bigint(Z0_dec, &zero);
	
	ascii_to_bigint(&bigint_prime_ascii, &prime);
	//print_bigint(&prime);
	//p_to_q(&prime, &q);
	//bigint_mod_sub(&zero, &q ,&k, &W);
	//print_bigint(&zero);
	//print_bigint(&q);
	//print_bigint(&W);
	//print_bigint(&k);
	

//---------------for testing monmul---------------//
	hex_to_bigint(testA, &A);
	hex_to_bigint(testB, &B);
	//
 //  bigint_sub(&A,&B,&C);
	//for(i=0; i<=INTMAX; i++) printf("%d ",C.hw[i]);
	//if(C.hw[0]==0)
	//	print_bigint(&C);
//bigint_mon_mul(&A, &B, &C, &prime);
//	print_bigint(&C);

	
	hex_to_bigint(bpx_dec, &bp.x);
	hex_to_bigint(bpy_dec, &bp.y);
	hex_to_bigint(curva_dec, &curv.a);
	hex_to_bigint(curvb_dec, &curv.b);
	hex_to_bigint(k_dec, &k);

	printf("prime is \n");
	print_bigint(&prime);
	printf("base point is \n");
	print_bigint(&bp.x);
	print_bigint(&bp.y);
	printf("curve is \n");
	print_bigint(&curv.a);
	print_bigint(&curv.b);
	printf("k is \n");
	print_bigint(&k);
	



	//bigint_edbl(&bp, &dp, &curv);
	//bigint_esum(&bp, &dp, &tp, &curv);
	//bigint_esum(&dp, &tp, &p5, &curv);

	my_bigint_emul(&k, &bp,&kp, &curv);
	//bigint_emul(&k, &bp,&kp1, &curv);
	//---------------------------------
	//bigint_mod_mul(&z1, &z1, &t1, &prime);
	//---------------------------------

	//printf("double point is \n");
	//print_bigint(&dp.x);
	//print_bigint(&dp.y);

	//printf("triple point is \n");
	//print_bigint(&dp1x);
	//print_bigint(&dp1y);

	//printf("double point is \n");
	//print_bigint(&dp2x);
	//print_bigint(&dp2y);

	//
	//printf("triple point is \n");
	//print_bigint(&tp.x);
	//print_bigint(&tp.y);

	//printf("5 times point is \n");
	//print_bigint(&p5.x);
	//print_bigint(&p5.y);

	printf("%s times point is \n",&k_dec);
	print_bigint(&kp.x);
	print_bigint(&kp.y);
	//printf("%s times point is \n",&k_dec);
	//print_bigint(&kp1.x);
	//print_bigint(&kp1.y);

}